package com.cgycms.webdeploy.controller;

import com.cgycms.webdeploy.auth.UserModel;
import com.cgycms.webdeploy.common.DeployConstant;
import com.cgycms.webdeploy.filter.SpringContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @ClassName : BaseController
 * @Description : 顶层
 * @Author : 王力超
 * @Date: 2020-08-19 15:26
 */
@Controller
public class BaseController {

    public HttpServletRequest getRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    public HttpServletResponse getResponse() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
    }

    public HttpSession getSession() {
        return getRequest().getSession();
    }

    public UserModel user() {
        UserModel user = (UserModel) getSession().getAttribute(DeployConstant.USER_SESSION_ID);
        return user;
    }

    protected Object getObject(String name) {
        return SpringContextHolder.getBean(name);
    }

}
